/**
 * 
 * @abstract
 * @class NG.command.Request
 * @extends Ext.util.Observable
 */
NG.command.Request = Ext.extend(Ext.util.Observable, {

	/**
	 * @type {app.model.Workspace}
	 */
	workspace:null,
	
	/**
	 * Property for while request's response is being waiting, whether loading panel will be shown
	 */
	showLoading: true,
	
	workspaceName: "",

	serviceName: "",
	
	serviceDependency: "",
	
	runXmlUrl: "",
	
	isValidUrl: "",
     
	errorStr: "",
	
	/**
	 * Used for data xml buffer.
	 */
	_dataXMLBuffer: null,
	
	/**
	 * Set null to data xml buffer.
	 * @function clearDataXMLBufer
	 */
	clearDataXMLBufer: function (){
		this._dataXMLBuffer = null;
	},
	
	/**
	 * 
	 * @param {String} xml xml formatted string
	 */
	setDataXMLBufer: function (xml){
		this._dataXMLBuffer = xml;
	},

	/**
	 * 
	 * @return {String} xml formatted buffered data
	 */
	getDataXMLBuffer: function (){
		return this._dataXMLBuffer;
	},
	
	getWorkspaceName: function (){
		return this.workspaceName;
	},
	
	getRunXmlUrl: function() {
		return this.runXmlUrl;
	},

	/**
	 * @type function
	 * @return {String}
	 */
	getIsValidUrl: function() {
		return this.isValidUrl;
	},
	
	/**
	 * Used by two types of requests
	 * 1: xml formed request for fetching data from server
	 * 2: request for related operation's validity check (permission etc.)
	 * 
	 * @returns {String} posted url 
	 */
	getPostUrl: function() {
		var ambiguousCheck = 0;
		var postedUrl = "";
		
		if (this.willBePostedForRunXml()) {
			postedUrl = this.runXmlUrl;
			++ambiguousCheck;
		}
		if (this.willBePostedForValidity()) {
			postedUrl = this.isValidUrl;
			++ambiguousCheck;
		}
		if ( ambiguousCheck == 0 ){
			throw "NOT VALID URL FOR POST (set runXmlUrl property)";
		}
		else if (ambiguousCheck > 1){
			throw "AMBIGUOUS URL FOR POST";
		}
		else {
			return postedUrl;
		}
	},
	
	willBePostedForValidity: function() {
		return !Ext.isEmpty(this.isValidUrl);
	},
	
	willBePostedForRunXml: function() {
		return !Ext.isEmpty(this.runXmlUrl);
	},
	
	/**
	 * Used for obtaining xml data
	 * 
	 * @return {String} formed xml structure
	 */
	getDataXML: function(){
		throw "getDataXML must bw overrided by extented classes";
	},
	
	/**
	 * Each request class has a response <br>
	 * Response object can be obtained over related request object
	 * 
	 * @param {String} xmlData - unparsed response data according to request
	 * return {NG.response.Response} response object related with request
	 */
	getResponse: function(xmlData){},

	/**
	 * Used for determining requested operation validity
	 * 
	 * @param responseData 
	 * @returns {Boolean} requested operation's validity
	 */
	isValid: function(responseData){
		var result = fleegix.xml.parse(fleegix.xml.createDoc(responseData), 'string').string;
		return ( result == "0" ? false : true );
	},
	
	/**
	 * This cache is used for runxml posts. Category, networkinfo ...
	 * @returns {String}
	 */
	getCacheKey: function (){
		return this.getWorkspaceName() + "-" + this.getRunXmlUrl();
	},
	
	constructor: function(config){
		NG.command.Request.superclass.constructor.call(this, config);
		//this.workspaceName = this.workspace != null ? this.workspace.getName() : "";
	},
	
	toString: function(){
		return this.serviceName;
	},
	
	/**
	 * Override this method for extended classes
	 * @returns {Boolean}
	 */
	validate: function () {
		return true;
	},
	
	/**
	 * 
	 * @return {NG.models.Workspace}
	 */
	getWorkspace: function () {
		return this.workspace;
	},

	/**
	 * 
	 * @return {String} error string
	 */
	getErrorStr: function () {
		return this.errorStr;
	}

	
});